package com.effective;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

class  Parent {
	public String supername;
	
	void getName() {System.out.println("Parent:" + supername);};

}

public class SubFromParent extends Parent implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public String subname;

	@Override
	void getName() {
		System.out.println("Subown  :" + subname);
		System.out.println("Subsuper:" + supername);
	}
	
	public static void main(String[] args) throws Exception {
		SubFromParent s = new SubFromParent();
		s.supername = "supertest";
		s.subname = "subtest";
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(bos);
		oos.writeObject(s);
		
		ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
		ObjectInputStream ois = new ObjectInputStream(bis);
		
		SubFromParent readObject = (SubFromParent) ois.readObject();
		bos.close();
		ois.close();
		readObject.getName();
	}
}/**
Output:
Subown  :subtest
Subsuper:null
*/
